package com.weavernorth.create;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
import weaver.general.BaseBean;
import weaver.workflow.webservices.WorkflowDetailTableInfo;
import weaver.workflow.webservices.WorkflowRequestTableField;
import weaver.workflow.webservices.WorkflowRequestTableRecord;

public class DetailWork {


    private static Log log = org.apache.commons.logging.LogFactory.getLog(DetailWork.class.getName());
    BaseBean bb =new BaseBean();
    public WorkflowRequestTableRecord[] detailWork(JSONArray workingJsonarry) {
        WorkflowRequestTableRecord[] wrtri = new WorkflowRequestTableRecord[workingJsonarry.size()];
        log.info("工作经历：" + workingJsonarry.size());
        if(workingJsonarry!=null) {
            WorkflowRequestTableField[] wrti;
            wrtri = new WorkflowRequestTableRecord[workingJsonarry.size()];
            //同一明细表可能存在多个，所以循环处理
            for (int i = 0; i < workingJsonarry.size(); i++) {
                JSONObject jsonObject = JSONObject.fromObject(workingJsonarry.get(i));

                //添加开始日期字段
                //从JSONobject中获取字段信息
                String strKsrq = jsonObject.getString("startDate");
                log.info("开始日期："+strKsrq);
                //数组有5个字段所以长度为5
                wrti = new WorkflowRequestTableField[5];
                wrti[0] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[0].setFieldName("ksrq");
                //赋值
                wrti[0].setFieldValue(strKsrq);
                wrti[0].setView(true);
                wrti[0].setEdit(true);

                //添加结束日期字段
                //从JSONobject中获取字段信息
                String strJsrq =jsonObject.getString("endDate");
                log.info("结束日期:"+strJsrq);
                wrti[1] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[1].setFieldName("jsrq");
                //赋值
                wrti[1].setFieldValue(strJsrq);
                wrti[1].setView(true);
                wrti[1].setEdit(true);

                //添加工作单位字段
                //从JSONobject中获取字段信息
                String strGzdw =jsonObject.getString("companyName");
                wrti[2] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[2].setFieldName("gzdw");
                //赋值
                wrti[2].setFieldValue(strGzdw);
                wrti[2].setView(true);
                wrti[2].setEdit(true);

                //添加工作部门字段
                //从JSONobject中获取字段信息
                String strGzbm = jsonObject.getString("department");
                wrti[3] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[3].setFieldName("gzbm");
                //赋值
                wrti[3].setFieldValue(strGzbm);
                wrti[3].setView(true);
                wrti[3].setEdit(true);

                //工作岗位
                //从JSONobject中获取字段信息
                String strGzgw = jsonObject.getString("jobTitle");
                wrti[4] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[4].setFieldName("gzgw");
                //赋值
                wrti[4].setFieldValue(strGzgw);
                wrti[4].setView(true);
                wrti[4].setEdit(true);


                wrtri[i] = new WorkflowRequestTableRecord();
                wrtri[i].setWorkflowRequestTableFields(wrti);
            }

        }


        return wrtri;
    }
}